package com.tanhua.sso.service;

import com.baidu.aip.face.AipFace;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

public class Sample {
    //设置APPID/AK/SK
    public static final String APP_ID = "24863196";
    public static final String API_KEY = "NuHwn8IVwkZPAu8NOPN2iTcZ";
    public static final String SECRET_KEY = "S1huxoK5qBT0O9ylWuyy22ve6AksYsXp";

    public static void main(String[] args) {
        // 初始化一个AipFace
        AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 可选：设置代理服务器地址, http和socket二选一，或者均不设置
//        client.setHttpProxy("proxy_host", proxy_port);  // 设置http代理
//        client.setSocketProxy("proxy_host", proxy_port);  // 设置socket代理

        // 调用接口
        String image = "https://super-souls.oss-cn-chengdu.aliyuncs.com/0df431adcbef76092120761bc65bebca7dd99e9c.jpg";
        String imageType = "URL";

        // 人脸检测
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("face_field", "age");
        options.put("max_face_num", "2");
        options.put("face_type", "LIVE");
        options.put("liveness_control", "LOW");
        JSONObject res = client.detect(image,imageType,options);
        try {
            System.out.println(res.get("result"));
            System.out.println(res.toString(2));
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }
}